// ActionScript file
import com.helloniu.fl.NCHandler;
import com.helloniu.fl.SOHandler;
import com.helloniu.fl.util.Tool;
import com.helloniu.fl.widget.HNCoreCompnent;
import com.helloniu.red5.info.UserInfo;

import flash.events.KeyboardEvent;
import flash.ui.Keyboard;

private var ncHandler:NCHandler = null;
private var soHandler:SOHandler = null;
private var _userID:String = null;

public function initConnection(ancHandler:NCHandler, asoHandler:SOHandler, auserID:String):void {
	this.ncHandler = ancHandler;
	this.soHandler = asoHandler;
	this._userID = auserID;
	this.soHandler.addChangeListener(statusChange);   
}

private function statusChange(asoHandler:SOHandler, pname:String = null, 
	oldValue:* = null, newValue:* = null):void 
{
    if(pname == null) {
        return;
    }

    newValue = asoHandler.getProperty(pname);

	if(pname == "ChatText") {
        processChatChange(newValue);
    }
}

private function processChatChange(val:*):void {
	chatLog.text = chatLog.text + " \n " + val;
}

private function chatKeyUp(evt:KeyboardEvent):void {    
	if(evt.keyCode == Keyboard.ENTER) {
    	var str:String = chatTxt.text;
    	str = _userID + ":" + str;
                
    	soHandler.setProperty("ChatText", str);
    	chatTxt.text = "";        
    }
}